package org.gwtEss.other;

import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;


public class Div extends Widget{
	Element el = DOM.createDiv();
	private Widget widget;

	public Div(String text) {
		super();
		el.setInnerText(text);
		setElement(el);
	}
	public Div(Widget widget) {
		super();
		setElement(el);
//	    DOM.appendChild(getElement(), widget.getElement());
		this.widget = widget; 
		DOM.appendChild(getElement(), widget.getElement());
	}
	
	public Div(String str, boolean isHtml) {
		super();
		if (isHtml)
			el.setInnerHTML(str);
		else 
			el.setInnerText(str);
		setElement(el);
	}

	public Div() {
		super();
		setElement(el);
	}
	public void setText(String text){
		el.setInnerText(text);
	}
/*	public void setHTML(String html){
		el.setInnerHTML(html);
	}
	public void setText(String text){
		el.setInnerText(text);
	}
	public String getHTML(){
		return el.getInnerHTML();
	}
	public String getText(){
		return el.getInnerText();
	}*/
	
	  public boolean remove(Widget w) {
	    // Validate.
	    if (widget != w) {
	      return false;
	    }

	    // Orphan.
//	    orphan(w);

	    // Physical detach.
	    getElement().removeChild(w.getElement());

	    // Logical detach.
	    widget = null;
	    return true;
	  }

	  public void setWidget(Widget w) {
		    // Validate
		    if (w == widget) {
		      return;
		    }

		    // Detach new child.
		    if (w != null) {
		      w.removeFromParent();
		    }

		    // Remove old child.
		    if (widget != null) {
		      remove(widget);
		    }

		    // Logical attach.
		    widget = w;

		    if (w != null) {
		      // Physical attach.
		      DOM.appendChild(getElement(), widget.getElement());
		    }
		  }

}